"""
多无人艇Boids模型围捕仿真系统启动文件
"""
import sys
import os
import argparse
from importlib import import_module

def main():
    parser = argparse.ArgumentParser(
        description="基于Boids模型的多无人艇围捕仿真系统",
        formatter_class=argparse.RawTextHelpFormatter
    )
    parser.add_argument(
        "example", type=str, choices=["simple", "fleeing", "multi"],
        help="选择要运行的示例:\n"
             "  simple  - 简单围捕（\n"
             "  fleeing - 逃逸目标围捕\n"
             "  multi   - 多目标围捕"
    )
    parser.add_argument("--usv_count", type=int, help="无人艇数量（仅适用于multi示例）")
    parser.add_argument("--target_count", type=int, help="目标数量（仅适用于multi示例）")
    parser.add_argument("--fleeing", action="store_true", help="启用目标逃逸行为（仅适用于multi示例）")
    parser.add_argument("--save_animation", type=str, help="保存动画到文件（需要ffmpeg）")
    parser.add_argument("--save_plot", type=str, help="保存指标图表到文件")
    
    args = parser.parse_args()
    
    try:
        if args.example == "simple":
            from usv_boids.examples.simple_surrounding import main as run_example
            run_example()
            
        elif args.example == "fleeing":
            from usv_boids.examples.fleeing_target import main as run_example
            run_example()
            
        elif args.example == "multi":
            # 处理参数
            multi_args=["--usv_count", "--target_count", "--fleeing", "--save_animation", "--save_plot"]
            module_args = []
            
            for arg in multi_args:
                arg_name = arg.lstrip('-')
                if arg_name == "fleeing" and args.fleeing:
                    module_args.append(arg)
                elif arg_name in vars(args) and vars(args)[arg_name] is not None and arg_name != "example":
                    module_args.append(arg)
                    module_args.append(str(vars(args)[arg_name]))
            
            sys.argv=[sys.argv[0]] + module_args
            from usv_boids.examples.multi_target_pursuit import main as run_example
            run_example()
            
    except ImportError as e:
        print(f"无法导入模块，{e}")
        sys.exit(1)
    except Exception as e:
        print(f"运行示例时发生错误，{e}")
        sys.exit(1)

if __name__ == "__main__":
    main() 